﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ISSMoviePlex.BLL;
using ISSMoviePlex.DAL.Models;

namespace ISSMoviePlex.Member.Controllers
{
    [Authorize(Roles = "Member")]
    public class TicketBookingController : Controller
    {
        TicketBookingBLL tktBookingBLL = new TicketBookingBLL();
        ScheduleBLL scheduleLogic = new ScheduleBLL();
        AccountBLL accountLogic = new AccountBLL();
        //
        // GET: /TicketBooking/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult BookTicket(int movieId)
        {
            return View(scheduleLogic.GetScheduleByMovie(movieId));
        }

        [HttpPost]
        public ActionResult BookTicket(int movieId, int scheduleId, int numberOfTicket = 0)
        {
            try
            {
                double discount;
                List<Ticket> tickets = tktBookingBLL.PerformBooking(numberOfTicket, scheduleId, accountLogic.GetCurrentUserId(), out discount);
                ViewBag.Discount = discount;
                return View("BookingDetails", tickets);
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return View(scheduleLogic.GetScheduleByMovie(movieId));
            }
        }
    }
}
